package org.devocean.groupbuying.web.frontend.displaybeans;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.devocean.groupbuying.domain.Article;
import org.devocean.groupbuying.domain.Comment;
import org.devocean.groupbuying.domain.Compatibility;
import org.devocean.groupbuying.domain.Formula;
import org.devocean.groupbuying.domain.Media;
import org.devocean.groupbuying.domain.Merchant;
import org.devocean.groupbuying.domain.Promotion;

public class PromotionBean {

	private Article article;
	private String mediaFilePath;
	private Promotion promotion;
	private Map<String, String> additionalContents;
	private Merchant merchant;
	private String merchantMediaFilePath;
	private List<Compatibility> compatibilities;
	private Integer stars;
	private List<Comment> comments;
	private String value;
	private String saving;
	private String planTitle;

	public PromotionBean(Promotion promotion) {
		this.article = promotion.getPlan().getProduct()
				.getArticlesLocalization().getArticles().iterator().next();
		this.promotion = promotion;
		System.out.println(promotion);

		setComments(new ArrayList<Comment>(article.getComments()));

		try {
			this.mediaFilePath = promotion.getPlan().getProduct()
					.getArticlesLocalization().getMediaLocalizations()
					.iterator().next().getMediaFilePath();
		} catch (Exception e) {
			// TODO : default image
			e.printStackTrace();
		}

		this.merchant = promotion.getPlan().getProduct().getMerchant();
		this.merchantMediaFilePath = promotion.getPlan().getProduct()
				.getMerchant().getArticlesLocalization()
				.getMediaLocalizations().iterator().next().getMediaFilePath();
		this.compatibilities = new ArrayList<Compatibility>();

		// Formula f = promotion.getPlan().getFormulas().iterator().next();
		// this.value = f.getPrice().toString();
		// if (promotion.getDiscount() != 0) {
		// this.saving = String.valueOf(((f.getPrice() * promotion
		// .getDiscount()) / 100));
		// } else {
		// this.saving = "0";
		// }

	}

	public String getMediaFilePath() {
		return mediaFilePath;
	}

	public void setMediaFilePath(String mediaFilePath) {
		this.mediaFilePath = mediaFilePath;
	}

	public Article getArticle() {
		return article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}

	public Promotion getPromotion() {
		return promotion;
	}

	public void setPromotion(Promotion promotion) {
		this.promotion = promotion;
	}

	public Map<String, String> getAdditionalContents() {
		return additionalContents;
	}

	public void setAdditionalContents(Map<String, String> additionalContents) {
		this.additionalContents = additionalContents;
	}

	public Merchant getMerchant() {
		return merchant;
	}

	public void setMerchant(Merchant merchant) {
		this.merchant = merchant;
	}

	public String getMerchantMediaFilePath() {
		return merchantMediaFilePath;
	}

	public void setMerchantMediaFilePath(String merchantMediaFilePath) {
		this.merchantMediaFilePath = merchantMediaFilePath;
	}

	public Set<Compatibility> getCompatibilities() {

		return this.promotion.getPlan().getCompatibilities();
	}

	public void setCompatibilities(List<Compatibility> compatibilities) {
		this.compatibilities = compatibilities;
	}

	public Integer getStars() {
		return stars;
	}

	public void setStars(Integer stars) {
		this.stars = stars;
	}

	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getSaving() {
		return saving;
	}

	public void setSaving(String saving) {
		this.saving = saving;
	}

	public String getPlanTitle() {
		Iterator<Article> it = promotion.getPlan().getArticlesLocalization().getArticles().iterator();
		return it.next().getTitle();
	}

	public void setPlanTitle(String planArticle) {
		this.planTitle = planArticle;
	}

}
